package com.jereh.topnews.demo;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;

import com.jereh.topnews.R;
import com.jereh.topnews.adapter.FragmentDemoPagerAdapter;

import java.util.ArrayList;
import java.util.List;

public class ViewPagerDemoActivity extends AppCompatActivity {

    private ViewPager pager;
    private FragmentDemoPagerAdapter adapter;
    private List<Fragment> list=new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_view_pager_demo);
        pager=(ViewPager)findViewById(R.id.pager);
        //初始化数据
        initFragment();
        adapter=new FragmentDemoPagerAdapter(getSupportFragmentManager(),list);
        pager.setAdapter(adapter);
    }
    private void initFragment(){
        int colors[]={R.color.colorAccent,R.color.colorPrimary,R.color.topGray,R.color.topRed,R.color.colorAccent};
        for(int i=0;i<5;i++){
            DemoFragment demoFragment=new DemoFragment();
            demoFragment.colorId=colors[i];
//            demoFragment.setFId(10+i);
            list.add(demoFragment);
        }
    }
}
